package teach.aistar.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import teach.aistar.model.entity.CarBrands;
import teach.aistar.model.entity.CarDetail;
import teach.aistar.model.entity.CarStyle;
import teach.aistar.model.vo.CarQueryVo;
import teach.aistar.service.IBuyCarsService;
import teach.aistar.service.ICarBandsService;
import teach.aistar.service.ICarStyleService;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.RequestWrapper;
import java.util.List;

@Controller
@RequestMapping("/car")
public class CarController {


    @Autowired
    IBuyCarsService iBuyCarsService;
    //    @Autowired
//    ICarStyleService iCarStyleService;
    @Autowired
    ICarBandsService iCarBandsService;

    @RequestMapping("/index03")
    public String show(HttpServletRequest req) {

        //获取pageNow
        String pageNow = req.getParameter("pageNow");
        if (null == pageNow || pageNow.trim().length() == 0) {
            pageNow = "1";
        }

        //判断更多条件是否显示
//        String count = req.getParameter("count");
//        if(count!=null){
//            req.setAttribute("count",count);
//        }

//        String typeId = req.getParameter("typeId");

//        String minPrice = req.getParameter("minPrice");
//        if(minPrice!=null){
//            req.setAttribute("minPrice",minPrice);
//        }

//        String searchName = req.getParameter("searchName");
//        CarQueryVo queryVo = new CarQueryVo();
//        queryVo.setName(searchName);
//        if(typeId!=null){
//            queryVo.setBrName(typeId);
//            req.setAttribute("typeId",typeId);
//        }
//        if(minPrice!=null && minPrice.trim().length()>0){
//            queryVo.setMinPrice(Double.valueOf(minPrice));
//        }
//
//        List<ProductType> productTypeList = productTypeService.findAll();
//        req.setAttribute("typeList",productTypeList);
//
//        if(searchName!=null && searchName.trim().length()>0){
//            req.setAttribute("searchName",searchName);
//        }


        PageInfo<CarDetail> pageInfo = iBuyCarsService.findAllx(Integer.valueOf(pageNow), 6);
        //PageInfo<CarDetail> pageInfo = iBuyCarsService.findAll(queryVo,Integer.valueOf(pageNow),6);

        List<CarBrands> carBrands = iCarBandsService.selectAll();

//        List<CarStyle> carStyles = iCarStyleService.findAll();

//        System.out.println(carStyles);
//        System.out.println(pageInfo);
        //放入到request作用域中
        req.setAttribute("pageInfo", pageInfo);

        req.setAttribute("carBrands", carBrands);

//        req.setAttribute("carStyles",carStyles);

        //转发到首页页面...
//        req.getRequestDispatcher("/WEB-INF/product/index.jsp").forward(req,resp);


        return "/orange/index";



//        return "/orange/index";




//        break;


    }

}
